# -*- coding: utf-8 -*-

import datetime
from uiview.pass_form_ui import Ui_Dialog as PassFormUI
from PyQt5.QtWidgets import QDialog
from PyQt5.QtSql import QSqlQuery

class PassFormWin(PassFormUI, QDialog):

    main_handle = None

    def __init__(self):
        super(PassFormWin, self).__init__()
        self.setupUi(self)

        self.closeBtn.clicked.connect(self.closeClick)
        self.submitBtn.clicked.connect(self.submitClick)

    def closeClick(self):
        self.close()

    def submitClick(self):
        host = self.host_in.text()
        account = self.acount_in.text()
        password = self.password_in.text()
        port = self.port_in.text()
        remark = self.remark_in.text()
        createtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        query = QSqlQuery()
        query.exec("INSERT INTO password (host, username, password, port, remark, createtime) VALUES ('"+host+"', '"+account+"', '"+password+"', '"+port+"', '"+remark+"', '"+createtime+"')")
        self.main_handle.recordQuery(0)
        self.close()